package com.test.SocketDemo;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

/**
 * ${DESCRIPTION}
 *
 * @author muxiaoyu
 * @create 2017/06/09 9:27
 **/
public class RemoteObjectClient {
    public static void main(String[] args) throws Exception {
        Socket socket = new Socket("172.16.4.205", 6655);
        List<String> hobbies = new ArrayList<String>();
        hobbies.add("football");
        hobbies.add("basketball");
        hobbies.add("music");
        ModObject modObject = new ModObject("mod1", 888, hobbies, "hehehehehe");
        System.out.println(modObject);
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
        objectOutputStream.writeObject(modObject);
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String line;
        StringBuffer sb = new StringBuffer();
        while ((line = bufferedReader.readLine()) != null) {
            sb.append(line);
        }
        System.out.println(sb.toString());
        objectOutputStream.close();
    }
}
